September 14, 2018

Plotly Interactive Graphic

The code for this interactive Plotly graphic is on the next slide.

Plotly Code for Graphic

mtcars$cyl <- factor(mtcars$cyl,
                     labels = c("4 cylinders",
                                "6 cylinders",
                                "8 cylinders"))
plot_ly(mtcars, x = ~wt, y = ~hp, type = "scatter", mode = "markers",
       color = ~cyl, size = ~mpg, hoverinfo = "text",
       text = ~paste("MPG:", mpg)) %>%
    layout(title = "Effect of Vehicle Weight, Horsepower, and Cylinders on MPG",
           xaxis = list(title = "Weight (1000 lbs)"),
           yaxis = list(title = "Horsepower"))

The plot on the previous slide shows the relationship between vehicle weight, horsepower, number of cylinders, and MPG fuel efficiency for cars from the mtcars dataset. It is evident that MPG is generally inversely proportional to weight and horsepower. Number of cylinders is also related to MPG, but it appears to primarily distinguish different clusters in the plot.